/**
 * 
 */
package com.hw.hcit.feature;

import java.io.FileOutputStream;
import java.io.IOException;

import android.util.Log;
import android.view.Window;
import android.view.WindowManager;
import android.content.ContentResolver;
import android.content.Context;
import android.graphics.Color;
import android.location.Address;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.os.IPowerManager;
import android.os.SystemProperties;
import com.hw.hcit.R;
import com.hw.hcit.conf.Config;
import com.hw.hcit.conf.JCtrlCallback;
import com.hw.hcit.conf.JTestItem;


/**
 * @author gaoshengpan
 *
 */
/*15-09-21 gaoshenpan add  VersionTestItem begin*/
public class VersionTestItem extends JTestItem implements OnClickListener {
    private static String KEY_HW_VERSION;
    private static String KEY_HW_INTERNAL_VERSION;
    private static String KEY_APCOM_TIME;
    private static String mUnknown = "null";
    private String TAG = "VersionTestItem";
    private ListView listView;
    private TextView verTextView, intVerTextView, acompTextView;
    private Button mButton1, mButton2;

    /**
     * @param cb
     */
    public VersionTestItem(JCtrlCallback cb) {
        super(cb);
        // TODO Auto-generated constructor stub
    }

    /**
    * 
    */
    public VersionTestItem() {
        // TODO Auto-generated constructor stub
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        KEY_HW_VERSION = getString(R.string.hw_version);
        KEY_HW_INTERNAL_VERSION = getString(R.string.hw_internal_version);
        KEY_APCOM_TIME = getString(R.string.hwcomp_time);

    }

    @Override
    public void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
        // setBackLight(LIGHTE_DEF);
    }

    /**
     * 
     */
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.version, container, false);
        verTextView = (TextView) rootView.findViewById(R.id.textView1);
        intVerTextView = (TextView) rootView.findViewById(R.id.textView2);
        acompTextView = (TextView) rootView.findViewById(R.id.textView3);
        mButton1 = (Button) rootView.findViewById(R.id.button2);
        mButton2 = (Button) rootView.findViewById(R.id.button3);
        mButton1.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                if (Config.CURR_PROJECT.isAuto()) {
                    if (!Config.ageingTested) {
                        rewriteOneByteOfNv2499(28, 'P');
                        Log.d("VersionTestItem", "--------->" + "p");
                    } else {
                        rewriteOneByteOfNv2499(59, 'P');
                    }
                }
                testFinish(true, 1, true);

            }
        });
        mButton2.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                if (Config.CURR_PROJECT.isAuto()) {
                    if (!Config.ageingTested) {
                        rewriteOneByteOfNv2499(28, 'F');
                        Log.d("VersionTestItem", "--------->" + "f");
                    } else {
                        rewriteOneByteOfNv2499(59, 'F');
                    }
                }
                testFinish(false, 1, false);

            }
        });
        return rootView;
    }

    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public void testFinish(boolean b) {
        // TODO Auto-generated method stub
        super.testFinish(b);
    }

    @Override
    public void testFinish(boolean b, int step, boolean onlyMove) {
        // TODO Auto-generated method stub
        super.testFinish(b, step, onlyMove);
    }

    @Override
    public void startTest() {
        // TODO Auto-generated method stub
        super.startTest();
    }

    @Override
    public void stopTest() {
        // TODO Auto-generated method stub
        super.stopTest();
    }

    @Override
    public void refresh() {
        // TODO Auto-generated method stub
        super.refresh();
    }

    /*
     * (non-Javadoc)
     * 
     * @see android.app.Fragment#onResume()
     */
    @Override
    public void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
        setSoftwareVersion();

    }

    private void setSoftwareVersion() {
        String softwareTitle = getSystemproString("ro.build.display.id");
        String internalSoftwareTitle = getSystemproString("ro.build.cust.id");
        /* gaoshenpan 15-08-20 fix hw-comptime begin */
        String softwareTime = getSystemproString("ro.build.date");
        /* gaoshenpan 15-08-20 fix hw-comptime end */
        Log.d(TAG, "softwareTime------->" + softwareTime);
        /*15-11-12 gaoshenpan fix ap-compile time no need split begin */
       /* if (softwareTime.length() > 18) {
            int nPos = softwareTime.indexOf(".");
            nPos = softwareTime.indexOf(".", nPos);
            softwareTime = softwareTime.substring(nPos + 1);
            Log.d(TAG, "softwareTime------->1" + softwareTime);
            nPos = softwareTime.indexOf(".");
            nPos = softwareTime.indexOf(".", nPos);

            softwareTime = softwareTime.substring(nPos + 1);
            Log.d(TAG, "softwareTime------->2" + softwareTime);

            StringBuffer time = new StringBuffer(softwareTime);
            time.insert(4, '-');
            time.insert(7, '-');
            
             * time.replace(10, 11, " "); time.insert(13, ':'); time.insert(16,
             * ':');
             
            softwareTime = time.toString();
        }*/
        /*15-11-12 gaoshenpan fix ap-compile time no need split end */
        verTextView.setText(KEY_HW_VERSION + "\n" + softwareTitle);
        intVerTextView.setText(KEY_HW_INTERNAL_VERSION + "\n"
                + internalSoftwareTitle);
        acompTextView.setText(KEY_APCOM_TIME + "\n" + softwareTime);

    }

    private static String getSystemproString(String property) {
        return SystemProperties.get(property, "unknown");
    }

    @Override
    public void onDestroy() {
        // TODO Auto-generated method stub

        super.onDestroy();
    }

    @Override
    public boolean dispatchKeyEvent(KeyEvent event) {
        // TODO Auto-generated method stub
        return true;
    }
}
/*15-09-21 gaoshenpan add  VersionTestItem begin*/
